import pygame
import time
import os
import tkinter as tk
from tkinter import messagebox

def play_music(files):
    pygame.init()
    pygame.mixer.init()

    while True:
        for file_path in files:

            # 检查文件是否存在
            if not os.path.exists(file_path):
                root = tk.Tk()
                root.withdraw()
                messagebox.showerror("文件不存在", f"程序错误！\n无法加载待播放的媒体资源，请检查此程序的运行目录下是否放置了以下三个需要在后台依次循环播放的音频文件！\nMusic1.flac\nMusic2.flac\nMusic3.flac\n")
                return

            pygame.mixer.music.load(file_path)
            pygame.mixer.music.play()

            # 等待播放结束
            while pygame.mixer.music.get_busy():
                time.sleep(1)

# 开始播放
if __name__ == "__main__":
    music_files = ["Music1.flac", "Music2.flac", "Music3.flac"]
    play_music(music_files)
